package com.hectopascal.service;

import com.hectopascal.auth.bean.AdminUserDetails;
import com.hectopascal.enums.UserRoleTypeEnum;
import com.hectopascal.mapper.UserMapper;
import com.hectopascal.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class MpUserDetailsService implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 1. 查询用户
        User user = userMapper.selectByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("用户不存在");
        }

        // 3. 构建UserDetails对象
        return new AdminUserDetails(user);
    }
}
